package ypmits.videoplayer.view {
	import ypmits.videoplayer.IVideoBuffer;

	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	/**
	 * @author ypmits
	 */
	public class VideoBufferDummy extends Sprite implements IVideoBuffer {
		private var timer : Timer;
		private var items : Array = new Array( );
		private var current : int = 0;
		private var numItems : int = 12;
		
		public function VideoBufferDummy() {
			var r : Number = 360 / numItems;
			for (var i : int = 0; i < numItems; i++) {
				var part : Sprite = new Sprite( );
				part.graphics.beginFill( 0xFFFFFF );
				part.graphics.drawCircle(0, -30, 5);
				part.graphics.endFill();
				part.rotation = r * i;
				items.push( part );
				addChild( part );
			}
			
			alpha = 0;
			visible = false;
			mouseEnabled = mouseChildren = false;
		}

		
		public function setPercentageBuffered( percentageBuffered : int ) : void {
			//trace( "BufferingWrapper.setPercentageBuffered(" + [ percentageBuffered ] + ")" );
		}	

		
		private function tHandler(event : TimerEvent) : void {
			var item : DisplayObject = items[ current ];
			item.scaleX = item.scaleY = 1;
			( current == items.length - 1 ) ? current = 0 : current++;
			item = items[ current ];
			item.scaleX = item.scaleY = 1.4;
		}
		
		
		
		public function show() : void
		{
			timer = new Timer( 50 );
			timer.addEventListener( TimerEvent.TIMER, tHandler );
			timer.start( );

			alpha = 1;
			visible = true;
		}
		
		
		
		public function hide() : void
		{
			if( timer ) {
				timer.removeEventListener( TimerEvent.TIMER, tHandler );
				timer.stop( );
				timer.reset( );
				timer = null;
			}

			alpha = 0;
			visible = false;
		}
	}
}
